home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 127_01.zip / RAP.C < prev    next >
Text File  |  1993-06-17  |  7KB  |  262 lines

  1. /*********************************************************************\
  2. ** .---------------------------------------------------------------. **
  3. ** |                                                               | **
  4. ** |                                                               | **
  5. ** |         Copyright (c) 1981, 1982, 1983 by Eric Martz.         | **
  6. ** |                                                               | **
  7. ** |                                                               | **
  8. ** |       Permission is hereby granted to use this source         | **
  9. ** |       code only for non-profit purposes. Publication of       | **
  10. ** |       all or any part of this source code, as well as         | **
  11. ** |       use for business purposes is forbidden without          | **
  12. ** |       written permission of the author and copyright          | **
  13. ** |       holder:                                                 | **
  14. ** |                                                               | **
  15. ** |                          Eric Martz                           | **
  16. ** |                         POWER  TOOLS                          | **
  17. ** |                    48 Hunter's Hill Circle                    | **
  18. ** |                      Amherst MA 01002 USA                     | **
  19. ** |                                                               | **
  20. ** |                                                               | **
  21. ** `---------------------------------------------------------------' **
  22. \*********************************************************************/
  23.  
  24. #include "rap.h"
  25.  
  26. main(argc, argv)
  27.     int argc;
  28.     char **argv;
  29.     {
  30.     char filename[FILENAME], *ptr;
  31.     int ignore_commands, arg, valid;
  32. #include <fio2.h>
  33.  
  34. /* EXPLICIT CALLS TO FORCE LINK FROM NDIO, NOT DEFF */
  35.     if (NO) getchar();
  36.     if (NO) putchar();
  37.     if (NO) fopen();
  38.     if (NO) fclose();
  39.  
  40.     fprintf(STDERR,
  41. "RAP Version 2.21  Copyright (c) 1981, 1982, 1983 by Eric Martz\n\n");
  42.  
  43.     if (argc  EQ  1) {
  44.         fprintf(STDERR,
  45.             "\nUSAGE:\n\nrap [name.ss] [-draft] [-p#] ");
  46.         fprintf(STDERR,"source_text_file_name\n");
  47.         fprintf(STDERR,
  48. "\t[ ) OR )filename OR )/list OR )/punch OR )/port OR\
  49.  )/screen]\n");
  50.         fprintf(STDERR,
  51.             "\n\t\t\t\t(more than one source_text_file_name OK)\n");
  52.         exit(0);
  53.     }
  54.  
  55.     init_defaults();
  56.     ignore_commands = NO;
  57.  
  58.     /* PROCESS '-...' ARGUMENTS AND SS ARGUMENT */
  59.  
  60. #ifdef DEBUG
  61.     if (argmatch("-DE*", &argc, argv, YES)) {
  62.         Debug = TRUE;
  63.         fprintf(STDERR,"Debug FLAG ON\n");
  64.     }
  65. #endif
  66.  
  67.     if (argmatch("-DR*", &argc, argv, YES)) {
  68.         Font = 1;
  69.         fprintf(STDERR,"\nDraft Font Selected.\n");
  70.     }
  71.     if (ptr = argmatch("-P*", &argc, argv, YES)) {
  72.         if (ati(&Print_at, ptr+2)) {
  73.             printf("Invalid starting page number after -p\n");
  74.             exit(0);
  75.         }
  76.         fprintf(STDERR, "\nBegin printing at page %d.\n", Print_at);
  77.     }
  78.     if (ptr = argmatch("*.SS", &argc, argv, YES)) {
  79.         if (badname(ptr)) exit(0);
  80.         strcpy(Ss_name, ptr);
  81.     }
  82.  
  83.     init_ss();
  84.  
  85. #ifdef DEBUG
  86.     if (Debug) fprintf(STDERR,"After INIT_SS: _Outflag = %d\n", _Outflag);
  87. #endif
  88.     *Out_file = 0;
  89.     if (argmatch("-I*", &argc, argv, YES)) {
  90.         strcpy(Out_file, "INDEX");
  91.         Index = YES;
  92.     }
  93.     if (argmatch("-C*", &argc, argv, YES)) {
  94.         strcpy(Out_file, "CONTENTS");
  95.         Tabcont = YES;
  96.     }
  97.     if (*Out_file) {
  98.         First_text = NO;
  99.         Print_at = 32000;
  100.         _Outflag = 16; /* FILE_OUT */
  101.         if (fcreat("TEMPOUT.$$$", _Dobuf) EQ ERROR) {
  102.             fprintf(STDERR, "\nCan't create %s; disk full?\n",
  103.             Out_file);
  104.             exit(0);
  105.         }
  106.     }
  107.     else dioinit(&argc, argv);    /* directed I/O */
  108.  
  109.     if (!_Outflag) _Outflag = LIST_OUT;
  110.  
  111. #ifdef DEBUG
  112.     if (Debug) fprintf(STDERR,"After DIOINIT: _Outflag = %d\n", _Outflag);
  113. #endif
  114.  
  115.     /* LOOP TO OPEN EACH FILENAME ARGUMENT IN TURN */
  116.     for (arg=1; arg < argc; arg++) {
  117.         strcpy (filename, argv[arg]);        /* get next argument */
  118. nx:
  119.         upper(filename);
  120.         if(badname(filename)) exit(0);
  121.         if (!Screen_size) fprintf(STDERR,
  122.             "\nNow processing \"%s\"\n",filename );
  123.         strcpy(Fn_main, filename);
  124.         Nxname[0] = NULL;
  125.         Fpin = fopen(filename,"r-");    
  126.         if (Fpin EQ 0) {
  127.             fprintf(STDERR,"Can not open \"%s\"\n", filename );
  128.             continue;
  129.         }
  130.         Fp_main = Fpin;
  131.         In_linecnt = 0;
  132.  
  133.         /* MAIN TEXT PROCESSING LOOP */
  134. goback:
  135.         while (anotherline(Inbuf)) {
  136.  
  137. #ifdef DEBUG
  138.             if (Debug) checkbig("Main gets anotherline:",Inbuf);
  139. #endif
  140.             /* SKIP DRAFT INPUT LINES */
  141.             if (Indraft AND !Printdraft AND
  142.                 (lefteq(Inbuf, ".ed") NE 3)
  143.                 ) continue;
  144.  
  145.             valid = YES;
  146.             if (Inbuf[0] EQ COMMAND
  147.                 AND
  148.                 (!ignore_commands OR (strcmp(Inbuf,".ic 0") EQ 0))) {
  149.  
  150.                 ignore_commands = command (Inbuf, Nxname, &valid);
  151.             }
  152.             else    text (Inbuf);
  153.             if (!valid) { /* process invalid command as text */
  154.                 valid = YES;
  155.                 text (Inbuf);
  156.             }
  157.         }
  158. #ifdef DEBUG
  159.         if (Debug) fprintf(STDERR,"Anotherline got EOF.\n");
  160. #endif
  161.         if (Fp_read EQ Fpin) {
  162.             if (!Screen_size) fprintf(STDERR,
  163.                 "\t...done reading \"%s\"\n", Fn_read);
  164.             Fpin = Fp_main;
  165.             fpfree(Fp_read);
  166.             Fp_read = 0;
  167. /*
  168.             New_portion = 0;
  169.             Old_portion = 0;
  170. */
  171.             In_linecnt = In_main;
  172.             goto goback;
  173.         }
  174.         if (!Screen_size) fprintf(STDERR,
  175.             "...done with \"%s\"\n", filename );
  176.         fpfree(Fpin);
  177.         if (Nxname[0]) {
  178.             strcpy(filename,Nxname);
  179.             goto nx;
  180.         }
  181.     } /* END OF TEXT FILENAME ARGUMENT PROCESSING LOOP */
  182.  
  183.     if (Lineno OR Outbuf[0]) space(HUGE);
  184.     dioflush();
  185.     if (Deinit) puts(Deinit);
  186.  
  187. } /* end main() */
  188.  
  189. /********************************************************************/
  190.  
  191. #include <fio3.h>
  192.  
  193. /********************************************************************/
  194.  
  195. /********************************************************************
  196.     initializes the global variables governing the execution of the
  197.      format commands.
  198. ********************************************************************/
  199. init_defaults() {
  200.     char *pnull;
  201.     
  202.     /* NOTE: BDSC V. 1.5 ZEROS ALL EXTERNALS, THEREFORE ALL WHICH
  203.     MUST BE SET TO ZERO ARE OMITTED FROM THE LIST BELOW */
  204.  
  205.     pnull = "";
  206.  
  207. #ifdef DEBUG
  208.     Debug = NO;
  209. #endif
  210.  
  211.     Bar = "- - - - - - - - - - - - - - -";
  212.     Blank_c = ' ';
  213.     Bo_on = pnull;
  214.     Bo_off = pnull;
  215.     Bo_shift = pnull;
  216.     Bo_restore = pnull;
  217.     Center_mode = pnull;
  218.     Con_forms = 1;
  219.     Exp_ctrl_chars = YES;
  220.     Fill  =  YES;/* yes we want filled lines */
  221.     First_text = YES;
  222.     Flush_left = pnull;
  223.     Flush_right = pnull;
  224.     Font_c = pnull;
  225.     Ignore_at = YES;
  226.     Just_one = pnull;
  227.     Just_two = pnull;
  228.     Lsval  =  1;/* line spacing  =  1 */
  229.     M1val  =  2;/* top and bottom margins */
  230.     M2val  =  2;
  231.     M3val  =  2;
  232.     M4val  =  2;
  233.     Newpag  =  1;
  234.     Nextout = Outbuf;
  235.     Pdata = -1;
  236.     Pival  =  Inval;
  237.     Plval  =  66;
  238.     Post_ss  = YES;
  239.     Post_ss_delim = '}';
  240.     Pre_ss  = YES;
  241.     Pre_ss_delim = '{';
  242.     Printdraft = YES;
  243.     Rev_lf = pnull;
  244.     Rmval  =  78;/* right margin  =  page width  */
  245.     Sanders = YES; /* assume sanders printer */
  246.     Tabval =  5;
  247.     Ul_on = pnull;
  248.     Ul_off = pnull;
  249.     Ul_restore = pnull;
  250.     Ul_shift = pnull;
  251.     
  252.     strcpy(Footer,"|-#-|");
  253.     strcpy(Ss_name, "DEFAULT.SS");
  254.  
  255.     Bottom  =  Plval - M3val - M4val;
  256. }
  257.  
  258. ;
  259. #endif
  260.  
  261.     Bar = "- - - - - - - - - - - - - - -";
  262.     Blank_c =